<?php
	/**
	 * 获取记录详情列表
	 */
    class CombatGainsdetail extends APIBase {
		
		public $tag = "CombatGainsdetail";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic(){              
			$date = $this->param['deskBuildDate'];
			$deskCode = $this->param['deskCode'];
			$playerID = $this->uid;
			//统计在同一deskBuildDate同一deskcode下玩家数据
			$UserCombatgainsdetail = $this->cache_redis->keys("hUserCombatgainsdetail:$playerID:$date:$deskCode:*");
			if(!empty($UserCombatgainsdetail)){
				$count = count($UserCombatgainsdetail);
				$result = array();
			    if ($count) {
				    foreach($UserCombatgainsdetail as $key=>$val){ 
					 $result[] = $this->cache_redis->hGetAll("hUserCombatgainsdetail:$playerID:$date:".$i);   
				    }
	            }
				$this->returnData($result);
			}else{	
			    //echo "<pre>";
				//统计在同一deskBuildDate同一deskcode下玩家数据
				$result = $this->mysql->select("customgamelog","SUM(score) as total,playerID,deskCode,pattern",array('deskBuildDate'=>$date,'deskCode'=>$deskCode),'GROUP BY playerID');	
				if(!empty($result)){
					$userinfo_tal = array();
					$patterns = '';
					foreach($result as $v){
							//$user = $this->mysql->select('player','id,name',array('id'=>$v['playerID']));
							$user = $this->data_redis->hMget("hu:".$v['playerID'],array('name','avater_url','id'));
							$userinfo_tal[] = array('point'=>$v['total'],'name'=>$user['name'],'playerID'=>$user['id']);
                            $patterns = $v['pattern'];	
					}
                }

			    //统计每一局的玩家数据			
				$row = $this->mysql->find("select playerID,gameDate FROM customgamelog where deskBuildDate=$date and deskCode=$deskCode  GROUP BY gameDate");
				$playtotal = count($row);
				$data = array();
				for($k=0;$k < count($row);$k++){
					$userinfo_sig = array();
					$gameDate = $row[$k]['gameDate'];
					$row0 = $this->mysql->find("select playerID,score FROM customgamelog where deskBuildDate=$date and deskCode=$deskCode and gameDate = $gameDate");
                    foreach($row0 as $v){
						//$user = $this->mysql->select('player','id,name',array('id'=>$v['playerID']));
						$user = $this->data_redis->hMget("hu:".$v['playerID'],array('name','avater_url','id'));
						$userinfo_sig[] = array('point'=>$v['score'],'name'=>$user['name'],'playerID'=>$v['playerID']);
					}
					$data[] = array('gameDate'=>$gameDate,'userinfo_sig'=>$userinfo_sig);
					//$this->cache_redis->hMset("hUserCombatgainsdetail:".$playerID.":$date:$deskCode:$k",array('detail'=>json_encode(array('gameDate'=>$gameDate,'userinfo_sig'=>$userinfo_sig))));
				}
				
				$detail = array('survey'=>$userinfo_tal,'detail'=>$data,'deskBuildDate'=>$date,'deskCode'=>$deskCode,'playtotal'=>$playtotal,'pattern'=>$patterns);

                $this->returnData($detail);					
				
			}
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
